package com.hsh.member.controller;


import com.hsh.member.base.Result;
import com.hsh.member.entity.Staff;
import com.hsh.member.req.StaffREQ;
import com.hsh.member.service.IStaffService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 员工信息表 前端控制器
 * </p>
 *
 * @author 海上花-www.hsh.com
 * @since 2022-12-01
 */
@RestController
@RequestMapping("/staff")
public class StaffController {
    /*
     分页条件查询 localhost:7777/list/search/1/20
     */
    @Autowired
    private IStaffService staffService;

    @PostMapping("/list/search/{page}/{size}")
    public Result search(@PathVariable("page") long page,
                         @PathVariable("size") long size,
                         @RequestBody(required = false)StaffREQ req
                         ){
       return staffService.search(page, size, req);
    }

    /*
    localhost:7777/staff
    添加员工信息
     */
    @PostMapping
    public  Result add(@RequestBody Staff staff){
        return staffService.add(staff);
    }

    /*
         localhost:7777/staff/id
         删除员工信息
     */
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable int id){
        boolean b = staffService.removeById(id);
        if(b){
            return  Result.ok();
        }
        return Result.error("删除员工信息失败");
    }

    //查询员工详情
    @GetMapping("/{id}")
    public  Result get(@PathVariable int id){
        Staff staff = staffService.getById(id);
        return Result.ok(staff);
    }

    //修改员工详情
    @PutMapping("/{id}")
    public Result update(@PathVariable int id,
                         @RequestBody Staff staff){
        return  staffService.update(id, staff);
    }


}
